#include <glf.h>
#include <glfwindow.h>

static void think(void* userdata)
{
    int* hasinit = userdata;
    if(!*hasinit){
        glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
        *hasinit = 1;
    }
}

static void render(void* userdata)
{
    /* swapping buffers is done by the mainloop implicitly */
    glClear(GL_COLOR_BUFFER_BIT);
}

static void resize(void* userdata)
{
    glViewport(0,0,glfGetWidth(),glfGetHeight());
}

int main(void)
{
    int hasinit = 0;
    
    glfConfigSetAttribute(glfMajorVersion, 3);
    glfConfigSetAttribute(glfMinorVersion, 0);
    glfConfigSetAttribute(glfMultiSampleLevel, 1);
    glfConfigSetAttribute(glfContextFlags, glfContextForwardCompatible);
    
    if( !glfCreateWindow( "GLF Empty Example", 1024, 768 ) )
        return -1;
    glfSetCallBack(glfCallbackThink, think, &hasinit);
    glfSetCallBack(glfCallbackRender, render, NULL);
    glfSetCallBack(glfCallbackResize, resize, NULL);
    
    glfMainloop();
    glfDestroyWindow();
    return 0;
}
